﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:controls="clr-namespace:Krempel.WP7.Core.Controls"
    xmlns:converters="clr-namespace:Krempel.WP7.Core.Converters"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone">

    <Style TargetType="controls:HtmlTextBlock">
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="BorderBrush" Value="{StaticResource PhoneTextBoxBrush}"/>
        <Setter Property="BorderThickness" Value="{StaticResource PhoneBorderThickness}"/>
        <Setter Property="FontFamily" Value="{StaticResource PhoneFontFamilyNormal}"/>
        <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeNormal}"/>
        <Setter Property="Foreground" Value="{StaticResource PhoneTextBoxForegroundBrush}"/>

        <Setter Property="H1Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
        <Setter Property="H1FontFamily" Value="{StaticResource PhoneFontFamilyNormal}"/>
        <Setter Property="H1FontSize" Value="{StaticResource PhoneFontSizeLarge}"/>
        <Setter Property="H1FontWeight" Value="Bold"/>
        <Setter Property="H1FontStyle" Value="Normal" />
        <Setter Property="H2Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
        <Setter Property="H2FontFamily" Value="{StaticResource PhoneFontFamilyNormal}"/>
        <Setter Property="H2FontSize" Value="{StaticResource PhoneFontSizeMedium}"/>
        <Setter Property="H2FontWeight" Value="Bold"/>
        <Setter Property="H2FontStyle" Value="Normal" />
        <Setter Property="H3Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
        <Setter Property="H3FontFamily" Value="{StaticResource PhoneFontFamilyNormal}"/>
        <Setter Property="H3FontSize" Value="{StaticResource PhoneFontSizeNormal}"/>
        <Setter Property="H3FontWeight" Value="Bold"/>
        <Setter Property="H3FontStyle" Value="Normal" />
        <Setter Property="HyperlinkForeground" Value="{StaticResource PhoneAccentBrush}"/>
        <Setter Property="HyperlinkFontFamily" Value="{StaticResource PhoneFontFamilyNormal}"/>
        <Setter Property="HyperlinkFontSize" Value="{StaticResource PhoneFontSizeNormal}"/>
        <Setter Property="HyperlinkFontWeight" Value="Normal"/>
        <Setter Property="HyperlinkFontStyle" Value="Normal" />
        <Setter Property="BlockQuoteBackground" Value="{StaticResource PhoneSubtleBrush}"/>

        <Setter Property="Padding" Value="6,0,6,4"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="controls:HtmlTextBlock">
                    <ItemsControl Padding="0" Name="PART_ItemsControl">
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <StackPanel />
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                    </ItemsControl>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="controls:DelayLoadImage">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="controls:DelayLoadImage">
                    <Grid x:Name="PART_Root">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="STATE_Default">
                                    <Storyboard>
                                        <DoubleAnimation Duration="0:0:1" To="1" Storyboard.TargetName="PART_DefaultImage" Storyboard.TargetProperty="Opacity" />
                                        <DoubleAnimation Duration="0:0:1" To="0" Storyboard.TargetName="PART_ActualImage" Storyboard.TargetProperty="Opacity" />
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="STATE_Actual">
                                    <Storyboard>
                                        <DoubleAnimation Duration="0:0:1" To="0" Storyboard.TargetName="PART_DefaultImage" Storyboard.TargetProperty="Opacity" />
                                        <DoubleAnimation Duration="0:0:1" To="1" Storyboard.TargetName="PART_ActualImage" Storyboard.TargetProperty="Opacity" />
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Image Name="PART_DefaultImage" Opacity="1" Canvas.ZIndex="-1" />
                        <Image Name="PART_ActualImage" Opacity="0" />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="controls:ReorderListBox">
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}" />
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" />
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="BorderBrush" Value="Transparent" />
        <Setter Property="Padding" Value="0" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="controls:ReorderListBox">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <ScrollViewer
                            x:Name="ScrollViewer"
                            Grid.ColumnSpan="2"
                            ManipulationMode="Control"
                            Foreground="{TemplateBinding Foreground}"
                            Background="{TemplateBinding Background}"
                            BorderBrush="Transparent"
                            BorderThickness="0"
                            Padding="{TemplateBinding Padding}">
                            <ItemsPresenter />
                        </ScrollViewer>
                        <Canvas
                            x:Name="DragInterceptor"
                            Grid.Column="1"
                            Margin="{TemplateBinding Padding}"
                            Background="Transparent"
                            VerticalAlignment="Stretch"
                            Width="52">
                            <Image
                                x:Name="DragIndicator"
                                Visibility="Collapsed">
                                <Image.RenderTransform>
                                    <TranslateTransform />
                                </Image.RenderTransform>
                            </Image>
                        </Canvas>
                        <Canvas
                            x:Name="RearrangeCanvas"
                            Grid.ColumnSpan="2"
                            Margin="{TemplateBinding Padding}"
                            Background="Transparent"
                            Visibility="Collapsed" />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="controls:ReorderListBoxItem">
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="BorderBrush" Value="Transparent" />
        <Setter Property="Padding" Value="0" />
        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        <Setter Property="VerticalContentAlignment" Value="Top" />
        <Setter Property="DragHandleTemplate">
            <Setter.Value>
                <DataTemplate>
                    <Canvas Width="52" Height="48" Background="Transparent">
                        <Polygon Fill="Gray" Points="16,20 4,20 22,4 22,44 16,44" />
                        <Polygon Fill="Gray" Points="32,28 44,28 26,44 26,4 32,4" />
                    </Canvas>
                </DataTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="controls:ReorderListBoxItem">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="*" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <Grid
                            x:Name="DropBeforeSpace"
                            Grid.Row="0"
                            Height="0">
                        </Grid>
                        <Grid
                            x:Name="DropAfterSpace"
                            Grid.Row="2"
                            Height="0">
                        </Grid>
                        <Border x:Name="LayoutRoot" Grid.Row="1" Background="{TemplateBinding Background}"  HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
                            <Grid Background="Transparent" Margin="{TemplateBinding Padding}">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="52" />
                                </Grid.ColumnDefinitions>
                                <ContentControl x:Name="ContentContainer" Grid.Column="0" Grid.ColumnSpan="2" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" Foreground="{TemplateBinding Foreground}" />
                                <Grid x:Name="HandleContainer" Grid.Column="1" Canvas.ZIndex="2">
                                    <ContentPresenter x:Name="DragHandle" Width="52" VerticalAlignment="Center" ContentTemplate="{TemplateBinding DragHandleTemplate}" />
                                </Grid>
                            </Grid>
                        </Border>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup
                                x:Name="CommonStates">
                                <VisualState x:Name="Normal" />
                                <VisualState x:Name="MouseOver" />
                                <VisualState x:Name="Disabled">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="LayoutRoot" Storyboard.TargetProperty="Background">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource TransparentBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <DoubleAnimation
                                            Storyboard.TargetName="ContentContainer"
                                            Storyboard.TargetProperty="Opacity"
                                            Duration="0"
                                            To=".5" />
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup
                                x:Name="SelectionStates">
                                <VisualState
                                    x:Name="Unselected" />
                                <VisualState
                                    x:Name="Selected">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames
                                            Storyboard.TargetName="ContentContainer"
                                            Storyboard.TargetProperty="Foreground">
                                            <DiscreteObjectKeyFrame
                                                KeyTime="0"
                                                Value="{StaticResource PhoneAccentBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup
                                x:Name="ReorderEnabledStates">
                                <VisualState
                                    x:Name="ReorderDisabled">
                                    <Storyboard>
                                        <DoubleAnimation
                                            Storyboard.TargetName="DragHandle"
                                            Storyboard.TargetProperty="Width"
                                            To="0"
                                            Duration="0" />
                                    </Storyboard>
                                </VisualState>
                                <VisualState
                                    x:Name="ReorderEnabled" />
                                <VisualStateGroup.Transitions>
                                    <VisualTransition
                                        From="ReorderDisabled"
                                        To="ReorderEnabled">
                                        <Storyboard>
                                            <DoubleAnimation
                                                Storyboard.TargetName="DragHandle"
                                                Storyboard.TargetProperty="Width"
                                                To="52"
                                                Duration="0:0:0.4" />
                                        </Storyboard>
                                    </VisualTransition>
                                    <VisualTransition
                                        From="ReorderEnabled"
                                        To="ReorderDisabled">
                                        <Storyboard>
                                            <DoubleAnimation
                                                Storyboard.TargetName="DragHandle"
                                                Storyboard.TargetProperty="Width"
                                                To="0"
                                                Duration="0:0:0.4" />
                                        </Storyboard>
                                    </VisualTransition>
                                </VisualStateGroup.Transitions>
                            </VisualStateGroup>
                            <VisualStateGroup
                                x:Name="DraggingStates">
                                <VisualState
                                    x:Name="NotDragging" />
                                <VisualState
                                    x:Name="Dragging">
                                    <Storyboard>
                                        <ColorAnimation
                                            Storyboard.TargetName="LayoutRoot"
                                            Storyboard.TargetProperty="(Control.Background).(SolidColorBrush.Color)"
                                            To="#60808080"
                                            Duration="0" />
                                        <DoubleAnimation
                                            Storyboard.TargetName="LayoutRoot"
                                            Storyboard.TargetProperty="Opacity"
                                            To="0.7"
                                            Duration="0" />
                                    </Storyboard>
                                </VisualState>
                                <VisualStateGroup.Transitions>
                                    <VisualTransition
                                        To="NotDragging">
                                        <Storyboard>
                                            <ColorAnimation
                                                Storyboard.TargetName="LayoutRoot"
                                                Storyboard.TargetProperty="(Control.Background).(SolidColorBrush.Color)"
                                                From="#60808080"
                                                Duration="0:0:0.2" />
                                            <DoubleAnimation
                                                Storyboard.TargetName="LayoutRoot"
                                                Storyboard.TargetProperty="Opacity"
                                                From="0.7"
                                                Duration="0:0:0.2" />
                                        </Storyboard>
                                    </VisualTransition>
                                    <VisualTransition
                                        To="Dragging">
                                        <Storyboard>
                                            <ColorAnimation
                                                Storyboard.TargetName="LayoutRoot"
                                                Storyboard.TargetProperty="(Control.Background).(SolidColorBrush.Color)"
                                                To="#60808080"
                                                Duration="0:0:0.2" />
                                            <DoubleAnimation
                                                Storyboard.TargetName="LayoutRoot"
                                                Storyboard.TargetProperty="Opacity"
                                                To="0.7"
                                                Duration="0:0:0.2" />
                                        </Storyboard>
                                    </VisualTransition>
                                </VisualStateGroup.Transitions>
                            </VisualStateGroup>
                            <VisualStateGroup
                                x:Name="DropIndicatorStates">
                                <VisualState
                                    x:Name="NoDropIndicator">
                                    <Storyboard>
                                        <DoubleAnimation
                                            Storyboard.TargetName="DropBeforeSpace"
                                            Storyboard.TargetProperty="Height"
                                            To="0"
                                            Duration="0" />
                                        <DoubleAnimation
                                            Storyboard.TargetName="DropAfterSpace"
                                            Storyboard.TargetProperty="Height"
                                            To="0"
                                            Duration="0" />
                                    </Storyboard>
                                </VisualState>
                                <VisualState
                                    x:Name="DropBeforeIndicator">
                                    <Storyboard>
                                        <DoubleAnimation
                                            Storyboard.TargetName="DropBeforeSpace"
                                            Storyboard.TargetProperty="Height"
                                            To="1"
                                            Duration="0" />
                                        <DoubleAnimation
                                            Storyboard.TargetName="DropAfterSpace"
                                            Storyboard.TargetProperty="Height"
                                            To="0"
                                            Duration="0" />
                                    </Storyboard>
                                </VisualState>
                                <VisualState
                                    x:Name="DropAfterIndicator">
                                    <Storyboard>
                                        <DoubleAnimation
                                            Storyboard.TargetName="DropBeforeSpace"
                                            Storyboard.TargetProperty="Height"
                                            To="0"
                                            Duration="0" />
                                        <DoubleAnimation
                                            Storyboard.TargetName="DropAfterSpace"
                                            Storyboard.TargetProperty="Height"
                                            To="1"
                                            Duration="0" />
                                    </Storyboard>
                                </VisualState>
                                <VisualStateGroup.Transitions>
                                    <VisualTransition
                                        From="NoDropIndicator"
                                        To="DropBeforeIndicator">
                                        <Storyboard>
                                            <DoubleAnimation
                                                Storyboard.TargetName="DropBeforeSpace"
                                                Storyboard.TargetProperty="Height"
                                                To="1"
                                                Duration="0:0:0.2" />
                                        </Storyboard>
                                    </VisualTransition>
                                    <VisualTransition
                                        From="NoDropIndicator"
                                        To="DropAfterIndicator">
                                        <Storyboard>
                                            <DoubleAnimation
                                                Storyboard.TargetName="DropAfterSpace"
                                                Storyboard.TargetProperty="Height"
                                                To="1"
                                                Duration="0:0:0.2" />
                                        </Storyboard>
                                    </VisualTransition>
                                    <VisualTransition
                                        From="DropBeforeIndicator"
                                        To="NoDropIndicator">
                                        <Storyboard>
                                            <DoubleAnimation
                                                Storyboard.TargetName="DropBeforeSpace"
                                                Storyboard.TargetProperty="Height"
                                                To="0"
                                                Duration="0:0:0.2" />
                                        </Storyboard>
                                    </VisualTransition>
                                    <VisualTransition
                                        From="DropAfterIndicator"
                                        To="NoDropIndicator">
                                        <Storyboard>
                                            <DoubleAnimation
                                                Storyboard.TargetName="DropAfterSpace"
                                                Storyboard.TargetProperty="Height"
                                                To="0"
                                                Duration="0:0:0.2" />
                                        </Storyboard>
                                    </VisualTransition>
                                    <VisualTransition
                                        From="DropBeforeIndicator"
                                        To="DropAfterIndicator">
                                        <Storyboard>
                                            <DoubleAnimation
                                                Storyboard.TargetName="DropBeforeSpace"
                                                Storyboard.TargetProperty="Height"
                                                To="0"
                                                Duration="0:0:0.2" />
                                            <DoubleAnimation
                                                Storyboard.TargetName="DropAfterSpace"
                                                Storyboard.TargetProperty="Height"
                                                To="1"
                                                Duration="0:0:0.2" />
                                        </Storyboard>
                                    </VisualTransition>
                                    <VisualTransition
                                        From="DropAfterIndicator"
                                        To="DropBeforeIndicator">
                                        <Storyboard>
                                            <DoubleAnimation
                                                Storyboard.TargetName="DropBeforeSpace"
                                                Storyboard.TargetProperty="Height"
                                                To="1"
                                                Duration="0:0:0.2" />
                                            <DoubleAnimation
                                                Storyboard.TargetName="DropAfterSpace"
                                                Storyboard.TargetProperty="Height"
                                                To="0"
                                                Duration="0:0:0.2" />
                                        </Storyboard>
                                    </VisualTransition>
                                </VisualStateGroup.Transitions>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style
        TargetType="controls:PullToRefreshPanel">
        <Setter
            Property="Background"
            Value="Transparent" />
        <Setter
            Property="PullingDownTemplate">
            <Setter.Value>
                <DataTemplate>
                    <TextBlock
                        Margin="0,16,0,0"
                        Style="{StaticResource PhoneTextGroupHeaderStyle}"
                        TextAlignment="Center"
                        FontStyle="Italic"
                        Text="Pull down to refresh." />
                </DataTemplate>
            </Setter.Value>
        </Setter>
        <Setter
            Property="ReadyToReleaseTemplate">
            <Setter.Value>
                <DataTemplate>
                    <TextBlock
                        Margin="0,16,0,0"
                        Style="{StaticResource PhoneTextGroupHeaderStyle}"
                        TextAlignment="Center"
                        FontWeight="Bold"
                        Text="Release to refresh!" />
                </DataTemplate>
            </Setter.Value>
        </Setter>
        <Setter
            Property="RefreshingTemplate">
            <Setter.Value>
                <DataTemplate>
                    <ProgressBar Margin="0,4,0,4" IsIndeterminate="True" />
                </DataTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="controls:PullToRefreshPanel">
                    <StackPanel x:Name="PullDownContainer" HorizontalAlignment="Stretch">
                        <StackPanel.Resources>
                            <converters:NegativeValueConverter x:Key="NegativeValueConverter" />
                        </StackPanel.Resources>
                        <StackPanel x:Name="PullingDownPanel" Background="{TemplateBinding Background}" Visibility="Collapsed">
                            <ContentPresenter ContentTemplate="{TemplateBinding PullingDownTemplate}" />
                        </StackPanel>
                        <StackPanel
                            x:Name="ReadyToReleasePanel"
                            Background="{TemplateBinding Background}"
                            Visibility="Collapsed">
                            <ContentPresenter
                                ContentTemplate="{TemplateBinding ReadyToReleaseTemplate}" />
                        </StackPanel>
                        <StackPanel
                            x:Name="RefreshingPanel"
                            Background="{TemplateBinding Background}"
                            Visibility="Collapsed">
                            <ContentPresenter
                                ContentTemplate="{TemplateBinding RefreshingTemplate}" />
                        </StackPanel>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="ActivityStates">
                                <VisualState x:Name="Inactive" />
                                <VisualState
                                    x:Name="PullingDown">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames
                                            Storyboard.TargetName="PullingDownPanel"
                                            Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame
                                                KeyTime="0"
                                                Value="Visible" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState
                                    x:Name="ReadyToRelease">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames
                                            Storyboard.TargetName="ReadyToReleasePanel"
                                            Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame
                                                KeyTime="0"
                                                Value="Visible" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState
                                    x:Name="Refreshing">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames
                                            Storyboard.TargetName="RefreshingPanel"
                                            Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame
                                                KeyTime="0"
                                                Value="Visible" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                    </StackPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>
